import time

from selenium.webdriver.common.by import By

from base.app_base_page import AppBasePage


class PageSpCart(AppBasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.__product_img = (By.ID, "com.tpshop.malls:id/product_pic_img")
        self.__add_cart_btn = (By.ID, "com.tpshop.malls:id/add_cart_tv")
        self.__ok_btn = (By.ID, "com.tpshop.malls:id/confirm_tv")
        self.__cart_btn = (By.ID, "com.tpshop.malls:id/bottom_cart_img")
        self.__add_cart_success = (By.ID, "com.tpshop.malls:id/product_name_tv")

    def page_sp_cart(self):
        self.app_base_click(self.__product_img)
        self.app_base_click(self.__add_cart_btn)
        self.app_base_click(self.__ok_btn)
        self.app_base_click(self.__cart_btn)

    def get_add_cart_success(self):
        time.sleep(1)
        return self.app_fd_element(self.__add_cart_success).text
